<script setup lang="ts">
import { ElConfigProvider } from 'element-plus';
import { ref, onErrorCaptured } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import zhCN from 'element-plus/es/locale/lang/zh-cn'; // 使用正确的路径
import en from 'element-plus/es/locale/lang/en'; // 使用正确的路径

const { locale } = useI18n();
const isRouterAlive = ref(true);
const router = useRouter();

onErrorCaptured((error) => {
  console.error('Captured error:', error);

  isRouterAlive.value = false;
  setTimeout(() => {
    isRouterAlive.value = true;
    router.push('/closed-management/access-control/personnel-passage');
  }, 0);
  return false;
});

// 根据 locale 的值返回对应的语言包对象
const getLocaleObject = () => {
  return locale.value === 'zh-CN' ? zhCN : en; // 根据实际需要添加更多语言
};
</script>

<template>
  <el-config-provider :locale="getLocaleObject()">
    <router-view v-if="isRouterAlive" />
  </el-config-provider>
</template>
